﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Pex.Framework.Packages;
using Microsoft.Pex.Engine.Packages;
using Microsoft.Pex.Engine.Explorable;
using Microsoft.Pex.Engine.ComponentModel;

namespace HintProvider
{
    /// <summary>
    /// Class that recommends factory methods
    /// </summary>
    [AttributeUsage(AttributeTargets.Assembly)]
    public class PexMeRecommenderAttribute
        : PexExecutionPackageAttributeBase, IPexExecutionPackage
    {       
        /// <summary>
        /// Invoked when a factory method is required
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        protected IEnumerable<IPexExplorableGuesser> CreateExplorableGuessers(IPexComponent host)
        {
            //host.Log.LogMessage(PexMeLogCategories.MethodBegin, "Begin of CreateExplorableGuessers method");            
            yield return new PexMeFactoryGuesser(host);
        }

        protected override object BeforeExecution(IPexComponent host)
        {
            //register all explorables
            foreach (IPexExplorableGuesser guesser in this.CreateExplorableGuessers(host))
            {
                host.Services.ExplorableGuesserManager.AddExplorableGuesser(guesser);
            }

            host.Log.LogMessage("factory guesser", "Initialized my factory guesser");
            return null;
        }        
    }
}
